<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<jsp:include page="/admin/header.jsp"></jsp:include>
<div class="main">
	<div class="body container">
		<div class="typecho-page-title">
			<h2>管理评论</h2>
		</div>
		<div class="row typecho-page-main" role="main">
			<div class="col-mb-12 typecho-list">
				<div class="clearfix">
					<ul class="typecho-option-tabs right">
						<li class=""><a
							href="${options.siteUrl}/admin/manage/comments?__typecho_all_comments=on">所有</a></li>
						<%-- <li class=" current"><a
							href="${options.siteUrl}/admin/manage/comments?__typecho_all_comments=off">我的</a></li> --%>
					</ul>
					<ul class="typecho-option-tabs">
						<li class="current"><a
							href="${options.siteUrl}/admin/manage/comments?status=published">已通过</a></li>
						<li><a
							href="${options.siteUrl}/admin/manage/comments?status=waiting">待审核
						</a></li>
						<!-- <li><a
							href="${options.siteUrl}/admin/manage-comments.php?status=spam">垃圾
						</a></li> -->
					</ul>
				</div>

				<div class="typecho-list-operate clearfix">
					<form method="get">
						<div class="operate">
							<label><i class="sr-only">全选</i><input type="checkbox"
								class="typecho-table-select-all"></label>
							<div class="btn-group btn-drop">
								<button class="btn dropdown-toggle btn-s" type="button">
									<i class="sr-only">操作</i>选中项 <i class="i-caret-down"></i>
								</button>
								<ul class="dropdown-menu">
									<!-- <li><a
										href="http://localhost/typecho/index.php/action/comments-edit?do=approved&_=53730b3352a84a7f8a5e2e305ca60430">通过</a></li>
									<li><a
										href="http://localhost/typecho/index.php/action/comments-edit?do=waiting&_=53730b3352a84a7f8a5e2e305ca60430">待审核</a></li>
									<li><a
										href="http://localhost/typecho/index.php/action/comments-edit?do=spam&_=53730b3352a84a7f8a5e2e305ca60430">标记垃圾</a></li>
									 -->
									<li><a lang="你确认要删除这些评论吗?"
										href="${options.siteUrl}/admin/manage?do=deleteComments">删除</a></li>
								</ul>
							</div>
						</div>
						<div class="search" role="search">
							<input type="text" class="text-s" placeholder="请输入关键字" value=""
								onclick="value=&#39;&#39;;name=&#39;keywords&#39;;">
							<button type="submit" class="btn btn-s">筛选</button>
						</div>
					</form>
				</div>
				<!-- end .typecho-list-operate -->

				<form method="post" name="manage_comments" class="operate-form">
					<div class="typecho-table-wrap">
						<table class="typecho-list-table">
							<colgroup>
								<col width="3%">
								<col width="6%">
								<col width="20%">
								<col width="71%">
							</colgroup>
							<thead>
								<tr>
									<th></th>
									<th>作者</th>
									<th></th>
									<th>内容</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach var="comment" items="${comments}">
									<tr id="comment-${comment['coid']}"
										data-comment="{&quot;author&quot;:&quot;\u5b64\u661f\u53ef&quot;,&quot;mail&quot;:&quot;webmaster@yourdomain.com&quot;,&quot;url&quot;:&quot;http:\/\/www.guxingke.com&quot;,&quot;ip&quot;:&quot;127.0.0.1&quot;,&quot;type&quot;:&quot;comment&quot;,&quot;text&quot;:&quot;0000000&quot;}">
										<td valign="top"><input type="checkbox"
											value="${comment['coid']}" name="coid[]"></td>
										<td valign="top">
											<div class="comment-avatar">
												<img class="avatar"
													src="http://www.guxingke.com/image/user/default.jpg"
													alt="${comment['author']}" width="40" height="40">
											</div>
										</td>
										<td valign="top" class="comment-head">
											<div class="comment-meta">
												<strong class="comment-author"><a
													href="${comment['url']}" rel="external nofollow"
													target="_blank">${comment['screenName']}</a></strong> <br>
												<%-- <span><a
													href="mailto:${msg.author.email}" target="_blank">${msg.author.email}</a></span> --%>
												<%-- <br> <span>${msg.author.ip}</span> --%>
											</div>
										</td>
										<td valign="top" class="comment-body">
											<div class="comment-date">
												${comment['created']} <a
													href="${options.siteUrl}/post/${comment['cid']}#comment-${comment['coid']}"
													target="_blank">####</a>
											</div>
											<div class="comment-content">
												<p>${comment['text']}</p>
											</div> <%-- <div class="comment-action hidden-by-mouse">
												<span class="weak">通过</span> <a
													href="http://localhost/typecho/index.php/action/comments-edit?do=waiting&coid=4&_=53730b3352a84a7f8a5e2e305ca60430"
													class="operate-waiting">待审核</a> <a
													href="http://localhost/typecho/index.php/action/comments-edit?do=spam&coid=4&_=53730b3352a84a7f8a5e2e305ca60430"
													class="operate-spam">垃圾</a> <a
													href="${options.siteUrl}/admin/manage-comments.php#comment-4"
													rel="http://localhost/typecho/index.php/action/comments-edit?do=edit&amp;coid=4&amp;_=53730b3352a84a7f8a5e2e305ca60430"
													class="operate-edit">编辑</a> <a
													href="${options.siteUrl}/admin/manage-comments.php#comment-4"
													rel="http://localhost/typecho/index.php/action/comments-edit?do=reply&amp;coid=4&amp;_=53730b3352a84a7f8a5e2e305ca60430"
													class="operate-reply">回复</a> <a lang="你确认要删除孤星可的评论吗?"
													href="http://localhost/typecho/index.php/action/comments-edit?do=delete&coid=4&_=53730b3352a84a7f8a5e2e305ca60430"
													class="operate-delete">删除</a>
											</div> --%>
										</td>
									</tr>
								</c:forEach>


							</tbody>
						</table>
						<!-- end .typecho-list-table -->
					</div>
					<!-- end .typecho-table-wrap -->

				</form>
				<!-- end .operate-form -->

				<div class="typecho-list-operate clearfix">
					<form method="get">
						<div class="operate">
							<label><i class="sr-only">全选</i><input type="checkbox"
								class="typecho-table-select-all"></label>
							<div class="btn-group btn-drop">
								<button class="btn dropdown-toggle btn-s" type="button">
									<i class="sr-only">操作</i>选中项 <i class="i-caret-down"></i>
								</button>
								<ul class="dropdown-menu">
									<!-- <li><a
										href="http://localhost/typecho/index.php/action/comments-edit?do=approved&_=53730b3352a84a7f8a5e2e305ca60430">通过</a></li>
									<li><a
										href="http://localhost/typecho/index.php/action/comments-edit?do=waiting&_=53730b3352a84a7f8a5e2e305ca60430">待审核</a></li>
									<li><a
										href="http://localhost/typecho/index.php/action/comments-edit?do=spam&_=53730b3352a84a7f8a5e2e305ca60430">标记垃圾</a></li>
									 -->
									<li><a lang="你确认要删除这些评论吗?"
										href="${options.siteUrl}/action/admin?do=deleteComments">删除</a></li>
								</ul>
							</div>
						</div>
					</form>
				</div>
				${pageNav }
				<!-- end .typecho-list-operate -->
			</div>
			<!-- end .typecho-list -->
		</div>
		<!-- end .typecho-page-main -->
	</div>
</div>
<jsp:include page="/admin/copyright.jsp"></jsp:include>
<jsp:include page="/admin/common-js.jsp"></jsp:include>
<script>
	(function() {
		$(document).ready(function() {
			$('.typecho-list-table').tableSelectable({
				checkEl : 'input[type=checkbox]',
				rowEl : 'tr',
				selectAllEl : '.typecho-table-select-all',
				actionEl : '.dropdown-menu a,button.btn-operate'
			});

			$('.btn-drop').dropdownMenu({
				btnEl : '.dropdown-toggle',
				menuEl : '.dropdown-menu'
			});
		});
	})();
</script>
<script type="text/javascript">
$(document).ready(function () {
    // 记住滚动条
    function rememberScroll () {
        $(window).bind('beforeunload', function () {
            $.cookie('__typecho_comments_scroll', $('body').scrollTop());
        });
    }

    // 自动滚动
    (function () {
        var scroll = $.cookie('__typecho_comments_scroll');

        if (scroll) {
            $.cookie('__typecho_comments_scroll', null);
            $('html, body').scrollTop(scroll);
        }
    })();

    $('.operate-delete').click(function () {
        var t = $(this), href = t.attr('href'), tr = t.parents('tr');

        if (confirm(t.attr('lang'))) {
            tr.fadeOut(function () {
                rememberScroll();
                window.location.href = href;
            });
        }

        return false;
    });

    $('.operate-approved, .operate-waiting, .operate-spam').click(function () {
        rememberScroll();
        window.location.href = $(this).attr('href');
        return false;
    });

    $('.operate-reply').click(function () {
        var td = $(this).parents('td'), t = $(this);

        if ($('.comment-reply', td).length > 0) {
            $('.comment-reply').remove();
        } else {
            var form = $('<form method="post" action="'
                + t.attr('rel') + '" class="comment-reply">'
                + '<p><label for="text" class="sr-only"><?php _e('内容'); ?></label><textarea id="text" name="text" class="w-90 mono" rows="3"></textarea></p>'
                + '<p><button type="submit" class="btn btn-s primary"><?php _e('回复'); ?></button> <button type="button" class="btn btn-s cancel"><?php _e('取消'); ?></button></p>'
                + '</form>').insertBefore($('.comment-action', td));

            $('.cancel', form).click(function () {
                $(this).parents('.comment-reply').remove();
            });

            var textarea = $('textarea', form).focus();

            form.submit(function () {
                var t = $(this), tr = t.parents('tr'), 
                    reply = $('<div class="comment-reply-content"></div>').insertAfter($('.comment-content', tr));
                
                reply.html('<p>' + textarea.val() + '</p>');
                $.post(t.attr('action'), t.serialize(), function (o) {
                    reply.html(o.comment.content)
                        .effect('highlight');
                }, 'json');

                t.remove();
                return false;
            });
        }

        return false;
    });

    $('.operate-edit').click(function () {
        var tr = $(this).parents('tr'), t = $(this), id = tr.attr('id'), comment = tr.data('comment');
        tr.hide();

        var edit = $('<tr class="comment-edit"><td> </td>'
                        + '<td colspan="2" valign="top"><form method="post" action="'
                        + t.attr('rel') + '" class="comment-edit-info">'
                        + '<p><label for="' + id + '-author"><?php _e('用户名'); ?></label><input class="text-s w-100" id="'
                        + id + '-author" name="author" type="text"></p>'
                        + '<p><label for="' + id + '-mail"><?php _e('电子邮箱'); ?></label>'
                        + '<input class="text-s w-100" type="email" name="mail" id="' + id + '-mail"></p>'
                        + '<p><label for="' + id + '-url"><?php _e('个人主页'); ?></label>'
                        + '<input class="text-s w-100" type="text" name="url" id="' + id + '-url"></p></form></td>'
                        + '<td valign="top"><form method="post" action="'
                        + t.attr('rel') + '" class="comment-edit-content"><p><label for="' + id + '-text"><?php _e('内容'); ?></label>'
                        + '<textarea name="text" id="' + id + '-text" rows="6" class="w-90 mono"></textarea></p>'
                        + '<p><button type="submit" class="btn btn-s primary"><?php _e('提交'); ?></button> '
                        + '<button type="button" class="btn btn-s cancel"><?php _e('取消'); ?></button></p></form></td></tr>')
                        .data('id', id).data('comment', comment).insertAfter(tr);

        $('input[name=author]', edit).val(comment.author);
        $('input[name=mail]', edit).val(comment.mail);
        $('input[name=url]', edit).val(comment.url);
        $('textarea[name=text]', edit).val(comment.text).focus();

        $('.cancel', edit).click(function () {
            var tr = $(this).parents('tr');

            $('#' + tr.data('id')).show();
            tr.remove();
        });

        $('form', edit).submit(function () {
            var t = $(this), tr = t.parents('tr'),
                oldTr = $('#' + tr.data('id')),
                comment = oldTr.data('comment');

            $('form', tr).each(function () {
                var items  = $(this).serializeArray();

                for (var i = 0; i < items.length; i ++) {
                    var item = items[i];
                    comment[item.name] = item.value;
                }
            });

            var html = '<strong class="comment-author">'
                + (comment.url ? '<a target="_blank" href="' + comment.url + '">'
                + comment.author + '</a>' : comment.author) + '</strong>'
                + ('comment' != comment.type ? '<small><?php _e('引用'); ?></small>' : '')
                + (comment.mail ? '<br /><span><a href="mailto:' + comment.mail + '">'
                + comment.mail + '</a></span>' : '')
                + (comment.ip ? '<br /><span>' + comment.ip + '</span>' : '');

            $('.comment-meta', oldTr).html(html)
                .effect('highlight');
            $('.comment-content', oldTr).html('<p>' + comment.text + '</p>');
            oldTr.data('comment', comment);

            $.post(t.attr('action'), comment, function (o) {
                $('.comment-content', oldTr).html(o.comment.content)
                    .effect('highlight');
            }, 'json');
            
            oldTr.show();
            tr.remove();

            return false;
        });

        return false;
    });
});
</script>
<jsp:include page="/admin/footer.jsp"></jsp:include>
